// pages/fenxing/fenxiang.js

import {
  ajax,
  src,
  util
} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    allmsg:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      idlist: options.idlist.split(",")
    })
    this.getall()
  },

  getall:function(){
    var that=this
    ajax('/appletShare', {
      data: {
        // userId: this.data.userId,
        id:that.data.idlist,
        
      },
      header: {
        "Accept": "application/json"
      },
      method: "post",
    }, res => {
      console.log(res,'获取图片成功')
      

      var filename = res.data.fileInfo.fileName


      let fileNameqian = filename.split(".")//取到文件名开始到最后一个点的长度
      let fileFormat = fileNameqian[1]
      res.data.fileInfo.fileFormat = fileFormat

      that.setData({
        allmsg:res.data
      })
    })
  },

  tohaibaofenxiang:function(){
    wx.navigateTo({
      url: '/pages/haibaofenxiang/haibaofenxiang?share=' + this.data.allmsg.share ,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  onPageScroll: function (e) {
    if (e.scrollTop < 0) {
      wx.pageScrollTo({
        scrollTop: 0
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },



  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

    // wx.stopPullDownRefresh()
    // var avatarUrl = this.data.allmsg.userInfo.pcAvatarUrl ? this.data.allmsg.userInfo.pcAvatarUrl : this.data.allmsg.userInfo.avatarUrl
    // var nickName = this.data.allmsg.userInfo.pcNickName ? this.data.allmsg.userInfo.pcNickName : this.data.allmsg.userInfo.nickName
    // var count = this.data.allmsg.count

    // console.log('/pages/shouxia/shouxia?idlist=' + this.data.idlist + '&avatarUrl=' + avatarUrl + '&nickName=' + nickName + '&count=' + count )

    var img = this.data.allmsg.picture //  分享图片

    var title = this.data.allmsg.describe
    return {
      title: title, //转发的标题
      path: '/pages/shouxia/shouxia?scene=' + this.data.allmsg.share ,
      imageUrl: img,
      success: (res) => {
        console.log("转发成功", res);
      },
      fail: (res) => {
        console.log("转发失败", res);
      }
    } //转发的图片
  }
})